<template>
 
  <PageForm :fromdata="null" :fromid="route.query.fromid" :instanceid="route.query.instanceid"      @callback="(e) => { 
        console.log(e);
        a_close();
    }" @errorcallback="() => {
        console.log('errorcallback');
    }">

  </PageForm>
</template>3
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useTab } from '../../layouts/composable/useTab'
import { layer } from '@layui/layer-vue'
import { useRoute, useRouter } from "vue-router";
import { useAppStore } from "../../store/app";
import webosutils from 'webosutils';
import { PageForm} from 'webos-form-design';



// import subform from '../../components/formitem/subform.vue';

    //const { change, close, currentPath } = useTab();
    const appStore = useAppStore();
    const router = useRouter();
    const route = useRoute();
    const {close,currentPath}  =useTab();
    const fromdata = ref({ name: "",data:[] }) as any;
    const validateModel = ref({});
    const layFormRef = ref(null) as any;

    // 校验
    const validate = function () {
      layFormRef.value.validate((isValidate: any, model: any, errors: any) => {
        if (!isValidate) {
          errors.forEach((item: any) => {
            layer.notify({
              title: "温馨提示",
              content: item.message
            });
            //layer.msg(item.message, { icon: 2, time: 1000 })
          });


          return;
        }
        var url = "";

        if (fromdata.value.form.url != "" && fromdata.value.form.url != undefined && fromdata.value.form.url != null) {
          url = fromdata.value.form.url;
        } else {
          url = "/v1/api/form/FormCommonTaskSave";
        }
       webosutils.http.post(url, { table: fromdata.value.form.table, data: JSON.stringify(model), istask: true, fromid: route.query.fromid }).then((res:any) => {
          console.log(res);

          if (res.success) {
            layer.notify({
              title: "温馨提示",
              content: res.msg
            });

            a_close();
          } else {
            layer.notify({
              title: "温馨提示",
              content: res.msg
            });


          }

        }).catch(resp => {
          layer.notify({
            title: "温馨提示",
            content: "网络错误"
          });


        })

      })
    }

    // 清除校验
    const clearValidate = function () {
      layFormRef.value.clearValidate();
    }

    // 重置表单
    const reset = function () {
      layFormRef.value.reset();

    }
    const a_close = () => {

    close(currentPath.value);

    }


</script>

<style lang="less" scoped>
.title {
  text-align: center;
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 20px;
  margin-top: 12px;
}

.describe {
  font-size: 14px;
  margin-bottom: 12px;
}

.footer {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 10px;
  box-sizing: border-box;
  background-color: #ffffff;
  border-top: 1px solid whitesmoke;
  line-height: 60px;
  height: 60px;

  .footer-button {
    right: 10px;
    position: absolute;
  }
}
</style>
